from typing import *
from math import inf

class Solution:
    def splitArray(self, nums: List[int], k: int) -> int:
        n = len(nums)
        f = [[inf] * (k + 1) for _ in range(n + 1)]
        f[0][0] = 0
        def min(a,b):
            return a if a<=b else b
        def max(a,b):
            return a if a>=b else b
        for j in range(1,k + 1):
            for i in range(j,n + 1):
                s = 0
                for p in range(i,j - 1,-1):
                    s+= nums[p - 1]
                    f[i][j] = min(f[i][j],max(f[p-1][j - 1] , s))
        return f[n][k]
    
s = Solution()
print(s.splitArray([1,4,4],
3))